<?php

Class ExploitationTypesController extends AppController {

    public $name = 'ExploitationTypes';

    function add($property_id) {
        $this->layout = "ajax";
        $this->set('property_id', $property_id);
        if (empty($this->data)) {
            
        } else {

            if ($this->ExploitationType->save($this->data)) {
                $this->Session->setFlash('Registro Adicionado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'ExploitationTypes', 'action' => 'index', $property_id));
            } else {
                $this->Session->setFlash('Error Guardando datos');
            }
        }
    }

    function edit($id) {
        $this->layout = "ajax";
        $this->set('property_id', $property_id);
        $this->ExploitationType->recursive = -1;
        if (empty($this->data)) {

            $this->data = $this->ExploitationType->find('first', array('conditions' => array('ExploitationType.id' => $id), 'fields' => array('ExploitationType.area', 'ExploitationType.tipo', 'ExploitationType.cultivo', 'ExploitationType.tipo_agricola', 'ExploitationType.tipo_pecuario', 'ExploitationType.property_id', 'ExploitationType.id')));
        } else {

            if ($this->ExploitationType->save($this->data)) {
                $this->Session->setFlash('Registro editado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'ExploitationTypes', 'action' => 'index', $this->data['ExploitationType']['property_id']));
            } else {
                $this->Session->setFlash('Error editando datos');
            }
        }
    }

    function index($property_id) {
        $this->layout = "ajax";
        $this->set('property_id', $property_id);
        $this->paginate = array('ExploitationType' => array('maxLimit' => 500, 'limit' => 50, 'fields' => array('ExploitationType.id', 'ExploitationType.area', 'ExploitationType.tipo', 'ExploitationType.id')));
        $this->set('ExploitationTypes', $this->paginate(array('ExploitationType.property_id' => $property_id)));
    }

    function select() {
        $this->layout = "ajax";
        $this->set('tipo', $this->data['ExploitationType']['tipo']);
    }

    function delete($exploitation_id, $property_id) {
        $this->layout = "ajax";
        if ($this->ExploitationType->delete($exploitation_id)) {
            $this->Session->setFlash('Registro eliminado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'ExploitationTypes', 'action' => 'index', $property_id));
        } else {
            $this->Session->setFlash('Error Eliminando datos');
        }
    }

}

?>